package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.domain.TravelAllSee;
import cn.wolfcode.trip.base.query.StrategyQueryObject;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.service.IStrategyDetailService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.service.ITravelAllSeeService;
import cn.wolfcode.trip.base.service.ITagService;
import cn.wolfcode.trip.base.util.UploadUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

//大攻略资源的控制器
@RestController
@RequestMapping("/strategies")
public class StrategyController {
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private IStrategyCatalogService catalogService;
    @Autowired
    private IStrategyDetailService detailService;
    @Autowired
    private ITravelAllSeeService seeService;
    @Autowired
    private ITagService tagService;

    /*
    获取推荐的大攻略(不分页)
    资源:/strategies
    动作:GET
    参数:state=2&pageSize=0
     */
    @GetMapping
    public Object getCommend(StrategyQueryObject qo) {
        return strategyService.query(qo);
    }

    /*
    根据攻略的id查询大攻略
    资源:/strategies/{id}
    动作:GET
    参数:
     */
    @GetMapping("/{id}")
    public Object getStrateById(@PathVariable Long id) {
        return strategyService.get(id);
    }

    /*
    查询某个大攻略下的攻略分类
    资源:/strategies/{id}/catalogs
    动作:GET
    参数:
     */
    @GetMapping("/{strategyId}/catalogs")
    public Object getCatalogsByStrategyId(@PathVariable Long strategyId) {
        List<StrategyCatalog> list = catalogService.list(strategyId);
        return list;
    }

    /*
    查询某篇攻略的文章内容
    资源:/strategies/details/{id}
    动作:GET
    参数:
     */
    @GetMapping("/details/{id}")
    public Object getDetailById(@PathVariable Long id) {
        return detailService.get(id);
    }

    /*
    查询某大攻略的中大家都在看的游记
    资源:/strategies/details/{id}
    动作:GET
    参数:
     */
    @GetMapping("/{strategyId}/travels")
    public Object getTravelsByStrategyId(StrategyQueryObject qo ){
        qo.setPageSize(0);
        return seeService.query(qo);
    }
    @GetMapping("/{strategyId}/tags")
    public Object getTagByStrategyId(@PathVariable Long strategyId) {
        return  tagService.getTagByStrategyId(strategyId);
    }
}
